/**
 * @Author wywinstonwy
 * @Date 2022/1/5 8:44 下午
 * @Description:
 */

import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/cupertino.dart';
import "package:flutter/material.dart";

class WyMediaQuery extends StatefulWidget {
  const WyMediaQuery({Key? key}) : super(key: key);

  @override
  _WyMediaQueryState createState() => _WyMediaQueryState();
}

class _WyMediaQueryState extends State<WyMediaQuery> {
  @override
  Widget build(BuildContext context) {
    //textScaleFactor 从1变到1.5，字体会全部增大
    var _data = MediaQuery.of(context).copyWith(textScaleFactor: 1);
    return Scaffold(
      appBar: getAppBar('MediaQuery'),
      body: MediaQuery(data: _data,
      child: _getDeviceMediaInfo(),),
    );
  }
  _getDeviceMediaInfo(){
    //屏幕大小
    Size mSize = MediaQuery.of(context).size;
    //密度
    double mRatio = MediaQuery.of(context).devicePixelRatio;
    //设备像素
    double width = mSize.width * mRatio;
    double height = mSize.height * mRatio;
    // 上下边距 （主要用于 刘海  和  内置导航键）
    double topPadding = MediaQuery.of(context).padding.top;
    double bottomPadding = MediaQuery.of(context).padding.bottom;
    double textScaleFactor = MediaQuery.of(context).textScaleFactor;

    Brightness platformBrightness = MediaQuery.of(context).platformBrightness;
    EdgeInsets viewInsets = MediaQuery.of(context).viewInsets;
    EdgeInsets padding = MediaQuery.of(context).padding;
    bool alwaysUse24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat;
    bool accessibleNavigation = MediaQuery.of(context).accessibleNavigation;
    bool invertColors = MediaQuery.of(context).invertColors;
    bool disableAnimations = MediaQuery.of(context).disableAnimations;
    bool boldText = MediaQuery.of(context).boldText;
    Orientation orientation= MediaQuery.of(context).orientation;
    // bool alwaysUse24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat;
    return Container(
      padding: EdgeInsets.all(30),
      child: Column(
      children: [
        Text('屏幕大小:${mSize.width} x ${mSize.height}',style: TextStyle(fontSize: 16),),
        Text('密度:${mRatio}',style: TextStyle(fontSize: 14),),
        Text('设备像素大小:${width} x ${height}',style: TextStyle(fontSize: 12),),
        Text('上边刘海:${topPadding}'),
        Text('下边导航:${bottomPadding}'),

        Text('textScaleFactor: ${textScaleFactor}'),
        Text('platformBrightness: ${platformBrightness}'),
        Text('viewInsets: ${viewInsets}'),
        Text('padding: ${padding}'),
        Text('alwaysUse24HourFormat: ${alwaysUse24HourFormat}'),
        Text('accessibleNavigation: ${accessibleNavigation}'),
        Text('invertColors: ${invertColors}'),
        Text('disableAnimations: ${disableAnimations}'),
        Text('boldText: ${boldText}'),
        Text('orientation: ${orientation}'),


      ],
    ),);



  }
}


